import store from "store"
import normalRequest from './normalRequest'
import {
	authChecker
} from "helpers/authHelper"
import {
	Base64
} from '../../commonjs/code.js'
var code = new Base64();
let date = new Date()
let year = date.getFullYear()
let month = date.getMonth() + 1
let day = date.getDate()
let signNum = code.encode((year + month * 2 + day * 3) * 2)

const authRequest = async (url, options = {}) => {
	let token = uni.getStorageSync('token');
	if (token == '') {
		const isLogin = await authChecker()
		if (isLogin) {
			options.header = {
				Authorization: 'Bearer ' + store.getters.accessToken,
				sign: signNum
			}
		}
	} else {
		options.header = {
			Authorization: 'Bearer ' + token,
			sign: signNum
		}
	}
	return await normalRequest(url, options)
}

export default authRequest
